﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Lhn.Ds.Core.Util
{
    public static class CRC8
    {
        public static int GetCRC(int[] data)
        {
            int crc = 0;
            int i = 0;
            int f = 0;
            var len = data.Length;
            while (len-- > 0)
            {
                crc = crc ^ data[f++];
                for (i = 0; i != 8; i++)
                {
                    if ((crc & 0x01) > 0)
                    {
                        crc = (crc >> 1) ^ 0x8c;
                    }
                    else
                    {
                        crc >>= 1;
                    }
                }
            }

            return crc;
        }
    }
}